package com.flavors.wan.main.ui;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.plat.sdk.okgo.callbck.XmResource;

import butterknife.ButterKnife;
import butterknife.Unbinder;

public abstract class BaseActivity extends AppCompatActivity {
    /**
     * 获取布局资源文件
     */
    protected abstract int getLayoutRes();

    /**
     * 初始化控件
     */
    protected abstract void initView();

    /**
     * 绑定数据
     */
    protected abstract void loadData();

    private Unbinder mUnbinder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getLayoutRes() > 0) {
            setContentView(getLayoutRes());
        }
        mUnbinder = ButterKnife.bind(this);//必须放在setContentView之后
        initView();
        loadData();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mUnbinder != null) {
            mUnbinder.unbind();
        }
    }

    /**
     * 在BaseActivity基类中增加这个目的是减少回调页面过多的显示造成的页面不清晰
     *
     * @param <T>
     */
    public class SimpleOnHandleCallBack<T> implements XmResource.OnHandleCallback<T> {
        @Override
        public void onLoading() {

        }

        @Override
        public void onSuccess(T data) {

        }

        @Override
        public void onFailure(String message) {

        }

        @Override
        public void onError(int code, String message) {

        }

        @Override
        public void onCompleted() {

        }
    }
}
